package com.xm.concurrent.base;

import com.xm.concurrent.base.util.SleepUtils;

import javax.sound.midi.Soundbank;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

/**
 * 4.2.4 过期的方法
 *
 * @author xiaoming
 * @date 2021-05-23 13:09
 */
public class DeprecatedThreadMethod {
    private static final Logger logger = Logger.getGlobal();

    public static void main(String[] args) {
        Thread thread = new Thread(new Runner(), "PrintThread");
        thread.setDaemon(true);

        thread.start();

        SleepUtils.second(3);
        // 暂停
        thread.suspend();
        logger.info("suspend");

        SleepUtils.second(3);
        // 继续
        thread.resume();
        logger.info("resume");

        SleepUtils.second(3);
        // 终止
        thread.stop();
        logger.info("stop");

        SleepUtils.second(3);

    }

    static class Runner implements Runnable {
        @Override
        public void run() {
            while (true) {
                // 每秒打印一次
                logger.info(Thread.currentThread().getName());
                SleepUtils.second(1);
            }
        }
    }


}
